﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PhatPhucLoc.model;
using System.Data;
using System.Data.SqlClient;
using PhatPhucLoc.util;
using System.Collections;

namespace PhatPhucLoc.dao
{
    class ReportDAO
    {
        public static ArrayList GetLoiNhuanNhomHang(DateTime startday, DateTime endday,int manhomhang)
        {
            ArrayList arr = new ArrayList();
            LoiNhuanNhomHang model = null;
            SqlParameter[] param = new SqlParameter[3];
            int i = 0;

            param[i] = new SqlParameter("Start", SqlDbType.DateTime);
            param[i++].Value = startday;
            param[i] = new SqlParameter("End", SqlDbType.DateTime);
            param[i++].Value = endday;
            param[i] = new SqlParameter("MaNhomHang", SqlDbType.Int);
            param[i++].Value = manhomhang;

            DataTable kq = DataUtil.executeStore("sp_NhomHang_LoiNhuan", param);
            if (kq.Rows.Count > 0)
            {
                foreach (DataRow row in kq.Rows)
                {
                    model = new LoiNhuanNhomHang();
                    model.Ten = row["ten"].ToString();
                    model.Loinhuan = double.Parse(row["LoiNhuan"].ToString());
                    model.Tonggiaban = double.Parse(row["TongGiaBan"].ToString());
                    model.Tonggianhap = double.Parse(row["TongGiaNhap"].ToString());
                    model.Soluong = int.Parse(row["SoLuong"].ToString());
                    arr.Add(model);
                }
            }
            return arr;
        }

        public static ArrayList GetLoiNhuanKhachHang(DateTime startday, DateTime endday, int makhachhang)
        {
            ArrayList arr = new ArrayList();

            LoiNhuanKhachHang model = null;
            SqlParameter[] param = new SqlParameter[3];
            int i = 0;

            param[i] = new SqlParameter("Start", SqlDbType.DateTime);
            param[i++].Value = startday;
            param[i] = new SqlParameter("End", SqlDbType.DateTime);
            param[i++].Value = endday;
            param[i] = new SqlParameter("MaKhachHang", SqlDbType.Int);
            param[i++].Value = makhachhang;

            DataTable kq = DataUtil.executeStore("sp_KhachHang_LoiNhuan", param);
            if (kq.Rows.Count > 0)
            {
                foreach (DataRow row in kq.Rows)
                {
                    model = new LoiNhuanKhachHang();
                    model.Ten = row["ten"].ToString();
                    model.Loinhuan = double.Parse(row["LoiNhuan"].ToString());
                    model.Tonggiaban = double.Parse(row["TongGiaBan"].ToString());
                    model.Tonggianhap = double.Parse(row["TongGiaNhap"].ToString());
                    model.Soluong = int.Parse(row["SoLuong"].ToString());
                    model.Tenkhachhang = row["tenkhachhang"].ToString();
                    arr.Add(model);
                }
            }
            return arr;
        }

        public static ArrayList GetLoiNhuanKhachHang1(DateTime startday, DateTime endday, int makhachhang)
        {
            ArrayList arr = new ArrayList();

            LoiNhuanKhachHang model = null;
            SqlParameter[] param = new SqlParameter[3];
            int i = 0;

            param[i] = new SqlParameter("Start", SqlDbType.DateTime);
            param[i++].Value = startday;
            param[i] = new SqlParameter("End", SqlDbType.DateTime);
            param[i++].Value = endday;
            param[i] = new SqlParameter("MaKhachHang", SqlDbType.Int);
            param[i++].Value = makhachhang;

            DataTable kq = DataUtil.executeStore("sp_KhachHang_LoiNhuan1", param);
            if (kq.Rows.Count > 0)
            {
                foreach (DataRow row in kq.Rows)
                {
                    model = new LoiNhuanKhachHang();
                    model.Ten = row["ten"].ToString();
                    model.Loinhuan = double.Parse(row["LoiNhuan"].ToString());
                    model.Tonggiaban = double.Parse(row["TongGiaBan"].ToString());
                    model.Tonggianhap = double.Parse(row["TongGiaNhap"].ToString());
                    model.Soluong = int.Parse(row["SoLuong"].ToString());
                    model.Tenkhachhang = row["tenkhachhang"].ToString();
                    arr.Add(model);
                }
            }
            return arr;
        }

        public static ArrayList GetLoiNhuanHangHoa(DateTime startday, DateTime endday)
        {
            ArrayList arr = new ArrayList();
            LoiNhuanNhomHang model = null;
            SqlParameter[] param = new SqlParameter[2];
            int i = 0;

            param[i] = new SqlParameter("Start", SqlDbType.DateTime);
            param[i++].Value = startday;
            param[i] = new SqlParameter("End", SqlDbType.DateTime);
            param[i++].Value = endday;

            DataTable kq = DataUtil.executeStore("sp_HangHoa_LoiNhuan", param);
            if (kq.Rows.Count > 0)
            {
                foreach (DataRow row in kq.Rows)
                {
                    model = new LoiNhuanNhomHang();
                    model.Ten = row["ten"].ToString();
                    model.Loinhuan = double.Parse(row["LoiNhuan"].ToString());
                    model.Tonggiaban = double.Parse(row["TongGiaBan"].ToString());
                    model.Tonggianhap = double.Parse(row["TongGiaNhap"].ToString());
                    model.Soluong = int.Parse(row["SoLuong"].ToString());
                    arr.Add(model);
                }
            }
            return arr;
        }
    }
}
